package exception;
import javax.jws.soap.SOAPBinding;
import java.io.*;
import java.util.Scanner;

public class ExceptionTest01 {
    public static void main(String[] args) throws IOException {
        //缓冲字符流的练习：PWDemo2简要记事本按行写+BRDemo按行读
/*        FileOutputStream fos = new FileOutputStream("fos.dat");
        OutputStreamWriter osw = new OutputStreamWriter(fos);
        BufferedWriter bw = new BufferedWriter(osw);
        PrintWriter pw = new PrintWriter(bw,true);
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入内容，单独输入exit时会退出");
        while (true){
            String line = sc.nextLine();
            if("exit".equals(line)){
                break;
            }
            pw.println(line);
        }
        pw.close();*/

/*        FileInputStream fis = new FileInputStream("fos.dat");
        InputStreamReader isr = new InputStreamReader(fis);
        BufferedReader br = new BufferedReader(isr);
        String line;
        while ((line = br.readLine())!=null){
            System.out.println(line);
        }
        br.close();*/

        // try...catch：TryCatchDemo
/*        System.out.println("程序开始了");
        try {
            String line = null;
            System.out.println(line.length());
        }catch (NullPointerException e){
            System.out.println("发生了空指针异常并且解决了");
        }catch (Exception e){
            System.out.println("出了错并且解决了");
        }
        System.out.println("程序结束了");*/

        //- finally：FinallyDemo+FinallyDemo2+AutoCloseableDemo
/*        System.out.println("程序解决了");
        try {
            String line = null;
            System.out.println(line.length());
        }catch (Exception e){
            System.out.println("出了错并且解决了");
        }finally {
            System.out.println("finally中的代码被执行了");
        }
        System.out.println("程序结束了");*/

/*        System.out.println("程序开始了");
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream("fos.dat");
        }catch (IOException e){
            System.out.println("出现IO异常并解决了");
        }finally {
            try {
                fos.close();
            }catch (Exception e){
                System.out.println("关闭流时出现异常并解决了");
            }
        }
        System.out.println("程序结束了");*/

/*        System.out.println("程序开始了");
        try(
                FileOutputStream fos = new FileOutputStream("");
        ){
            fos.write(1);
        }catch (IOException e){
            e.printStackTrace();
        }
        System.out.println("程序结束了");*/

        //throw:Student+ThrowDemo
/*        private int age;

        public int getAge() {
            return age;
        }

        public void setAge(int age) {
            if (age <0 || age>100){
                throw  new RuntimeException();//抛出一个异常
            }
            this.age = age;
        }*/

/*        Student zs = new Student();
        try {
            zs.setAge(1000);
            System.out.println("此人的年龄为"+ zs.getAge());
        } catch(RuntimeException e){
            System.out.println("年龄不合法");
        }*/
    }
}
